//
//  ZDBIntegralAlearView.m
//  ZDB
//
//  Created by Kk on 2020/4/12.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBIntegralAlearView.h"

@interface ZDBIntegralAlearView()
#pragma make --控件
@property(nonatomic,strong)UIView * bgView;
@property(nonatomic,strong)UILabel * titleLab;
@property(nonatomic,strong)UILabel * contentLab;
@end
@implementation ZDBIntegralAlearView

- (instancetype)initWithtititle:(NSString *)title
                         cancel:(NSString *)cancel;
{
    if (self=[super init])
       {
           self.frame=[UIScreen mainScreen].bounds;
           self.backgroundColor=[UIColor colorWithWhite:.0 alpha:.6];
           self.userInteractionEnabled = YES;
           UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
           [self addGestureRecognizer:tap];
           
           [self addSubview:self.bgView];
           [_bgView addSubview:self.contentLab];
           [_bgView addSubview:self.titleLab];
           [self.bgView addSubview:self.cancelBtn];
           
           _titleLab.text = title;
           
           
       }
       return self;
}

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, UIScreenWidth-40, 0)];
        _bgView.center =self.center;
        _bgView.backgroundColor=WHITECOLOR;
        KViewRadius(_bgView, 4);
    }
    return _bgView;
}
- (UILabel *)contentLab
{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, UIScreenWidth-80, 0)];
       
        _contentLab.textColor = MAINTITLECOLOR1;
        _contentLab.font = AutoFont(14);
        _contentLab.numberOfLines = 0;
        NSString * str  = @"1.用户可以通过参与，签到，观看广告，完成任务，获得积分;、\n2.积分累计达到一定数额可以提升vip等级;\n3.积分可在兑换中心消耗积分兑换商品;\n4.一切积分的使用和解释权归本APP所有;";
        _contentLab.attributedText = [ZBDUnit finderattributedLinesString:str attributedString:str color:MAINTITLECOLOR1 font:AutoFont(11)];
        [_contentLab sizeToFit];
        
        CGFloat conten_h = _contentLab.height;
        _bgView.height = conten_h +100;
        _bgView.center =self.center;
        _contentLab.frame = CGRectMake(20, 60, _bgView.width-40, conten_h);
        
    }
    return _contentLab;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _bgView.width, 50)];
        _titleLab.font = AutoBoldFont(16);
        _titleLab.textColor = MAINTITLECOLOR;
        _titleLab.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLab;
}
- (UIButton *)cancelBtn
{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(_bgView.width -RealValue_W(100)-10 , 0, RealValue_W(100), RealValue_W(100))];
        [_cancelBtn setTitle:@"取消" forState:0];
        _cancelBtn.titleLabel.font = AutoFont(15);
        [_cancelBtn setTitleColor:MAINTITLECOLOR forState:0];
        _cancelBtn.centerY = _titleLab.centerY;
        [_cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:(UIControlEventTouchUpInside)];
       
      
    }
    return _cancelBtn;
}
- (void)dismiss
{
   [self dismissAlertView];
    
}
-(void)dismissAlertView
{
    [self removeFromSuperview];
    
}
-(void)showLXAlertView
{
    [kWindow addSubview:self];
    [self setShowAnimation];
}
-(void)setShowAnimation{
    WeakSelf;
    switch (_animationStyle) {
            
        case LXASAnimationDefault:
        {
            [UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                [weakSelf.bgView.layer setValue:@(0) forKeyPath:@"transform.scale"];
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.23 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    [weakSelf.bgView.layer setValue:@(1.2) forKeyPath:@"transform.scale"];
                } completion:^(BOOL finished) {
                    [UIView animateWithDuration:0.09 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                        [weakSelf.bgView.layer setValue:@(.9) forKeyPath:@"transform.scale"];
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:0.05 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                            [weakSelf.bgView.layer setValue:@(1.0) forKeyPath:@"transform.scale"];
                        } completion:^(BOOL finished) {
                            weakSelf.userInteractionEnabled = YES;
                        }];
                    }];
                }];
            }];
        }
            break;
            
        case LXASAnimationLeftShake:{
            
            CGPoint startPoint = CGPointMake(-_bgView.width, self.center.y);
            weakSelf.bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationTopShake:{
            
            CGPoint startPoint = CGPointMake(self.center.x, -_bgView.frame.size.height);
            _bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationNO:{
            
        }
            
            break;
            
        default:
            break;
    }
}
-(void)cancelclick
{
    [self dismissAlertView];
}
@end
